package com.algorithm;

public class QuickSort {

    public static void main(String[] args) {
        int[] ints = {4, 5, 6, 7, 1, 2, 3};
        sort(ints, 0, ints.length - 1);
        for (int i : ints) {
            System.out.print(i + ",");
        }
    }

    public static void sort(int[] ints, int low, int high) {
        if (low >= high) {
            return;
        }

        int l = low, h = high, t = ints[low];

        while (l < h) {

            while (ints[h] >= t && l < h) {
                h--;
            }

            while (ints[l] <= t && l < h) {
                l++;
            }

            int tmp = ints[l];
            ints[l] = ints[h];
            ints[h] = tmp;
        }

        int tmp = ints[low];
        ints[low] = ints[l];
        ints[l] = tmp;

        sort(ints, low, l - 1);
        sort(ints, l + 1, high);
    }

}
